/******************************************************************************
/
/  Authors:
/           Ilan   Bar Magen 
/    		Shalev Mintz      066078189  shalevmi@t2  
/
/  Submition date: 9/7/2008
/
/  This file contains:
/
/
******************************************************************************/

#ifndef STADIUM_H 
#define STADIUM_H


#include "DSL.h"

#include<cstdlib>  // for NULL
#include<iostream>

using namespace std;



class Fan{
private:
	int ID;
	int stand;
	int chair;
	int team;
	bool isBanned;

public:
	Fan(int _ID, int _stand, int _chair, int _team, bool _isBanned = false):
	 ID(_ID), stand(_stand), chair(_chair), team(_team), isBanned(_isBanned) {}

	int  GetID()       const {return ID;}
	int  GetStand()    const {return stand;}
	int  GetChair()    const {return chair;}
	int  GetTeam()     const {return team;}
	bool GetIsBanned() const {return isBanned;}

	void SetID(int id)        {ID = id; return;}
	void SetStand(int st)     {stand = st; return;}
	void SetChair(int ch)     {chair = ch; return;}
	void SetTeam(int te)      {team = te; return;}
	void SetIsBanned(bool ba) {isBanned = ba; return;}
};


SL_RESULT Release_data(Fan** dat);


template <class D, class K>
class Stand : public DRSkip_List<D, K>{
private:
    int MaccabiFans,
		HapoelFans;
public:
	Stand(): DRSkip_List<D,K>(INT_MAX, INT_MIN) {MaccabiFans = HapoelFans = 0;}

	int getMaccabiFans() const {return MaccabiFans;}
	int getHapoelFans()  const {return HapoelFans;}

	void IncTeam(int tm) 
	{
		if (tm ==  0) ++MaccabiFans;
		else ++HapoelFans;
	}

	void DecTeam(int tm) 
	{
		if (tm ==  0) --MaccabiFans;
		else --HapoelFans;
	}

};



class Stadium{
private:
	const int S;
	Stand<Fan*,int>* Stands; 
	DRSkip_List<Fan*, int> FansByID;
public:
	Stadium(int _S): S(_S),FansByID(INT_MAX, INT_MIN) {Stands = new Stand<Fan*,int>[S];}
	~Stadium() {
		FansByID.For_Each_Node(Release_data); //TODO check result
		delete[] Stands;
	};  

	StatusType newFan(int id, int stand, int chair, int team);
	StatusType banFan(int stand, int chair);
	StatusType getChair(int id, int * stand, int * chair);
	StatusType getNumMaccabiFans(int stand, int * numFans);
	StatusType getNumHapoelFans(int stand, int * numFans);
	StatusType getNumFreeChairs(int stand, int chair, int * freeChairs);
	StatusType separateStands(int stand1, int stand2);
	int        isImplementingBonus() const {return 0;}
};




#endif //STADIUM_H
